include $(TOPDIR)/rules.mk

#这里定义了安装包的名字，版本，编译路径
LUCI_TITLE:=HLG Idc Energy
LUCI_PKGARCH:=all
PKG_NAME:=hlg-idc-energy
PKG_VERSION:=1.0
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk #如果使用cmake，则必须增加此行
#定义了在menuconfig的时候，出现在的位置，以及标题
define Package/${PKG_NAME}
	SECTION:=hlg
	CATEGORY:=HLG
	SUBMENU :=
	TITLE:=hlg idc energy project.
	DEPENDS:=+libuci +libhiredis +cJSON +libpthread +libubus +libubox +libblobmsg-json
endef

#定义了简介内容
define Package/${PKG_NAME}/description
	this is a description
endef
#设置启动脚本的执行权限
define Package/${PKG_NAME}/postinst

endef
#这里是编译准备阶段的操作
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

#这里是安装阶段的操作，包括各种拷贝文件
define Package/${PKG_NAME}/install
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/idc_energy $(1)/bin/
	$(INSTALL_BIN) files/script/bin/* $(1)/bin

	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DATA) files/config/* $(1)/etc/config

	$(INSTALL_DIR) $(1)/usr/share/rpcd/acl.d
	$(INSTALL_DATA) luci/acl.d/* $(1)/usr/share/rpcd/acl.d

	$(INSTALL_DIR) $(1)/usr/share/luci/menu.d
	$(INSTALL_DATA) luci/menu.d/* $(1)/usr/share/luci/menu.d

	$(INSTALL_DIR) $(1)/www/luci-static/resources/view/idc_web
	$(INSTALL_DATA) luci/view/* $(1)/www/luci-static/resources/view/idc_web

	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_DATA) files/init.d/* $(1)/etc/init.d
	chmod 755 $(1)/etc/init.d/idc_energy

endef

#这里是执行编译
$(eval $(call BuildPackage,hlg-idc-energy))

